package crmdna.client.isha;

import java.util.Set;

import javax.inject.Named;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.appengine.api.users.User;

import crmdna.client.isha.IshaConfig.IshaConfigProp;
import crmdna.common.APIResponse;
import crmdna.common.APIResponse.Status;
import crmdna.common.Utils;

@Api(name = "isha")
public class IshaConfigApi {

	@ApiMethod(path = "get", httpMethod = HttpMethod.GET)
	public APIResponse get() {
		try {

			IshaConfigProp prop = IshaConfig.safeGet();
			return new APIResponse(Status.SUCCESS, prop);

		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}

	@ApiMethod(path = "setSathsangPracticeIds", httpMethod = HttpMethod.POST)
	public APIResponse setSathsangPracticeIds(
			@Named("sathsang_practice_ids") Set<Long> practiceIds, User user) {
		try {

			IshaConfigProp prop = IshaConfig.setSathsangPractices(practiceIds,
					Utils.getLoginEmail(user));
			return new APIResponse(Status.SUCCESS, prop);

		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}
}
